package com.CGFrame.struts.action.project;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Catemodel;
import com.CGFrame.struts.POJOs.Elementgroup;
import com.CGFrame.struts.POJOs.Shotgroup;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.struts.bean.project.ProjectBean;
import com.CGFrame.struts.bean.unit.ElementGroupBean;
import com.CGFrame.struts.bean.unit.ShotGroupBean;

public class IndexShotModelAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String projectId=request.getParameter("projectId");
		ProjectOperate pop=ProjectOperateFactory.getprojectOperate();
		ProjectBean pb=new ProjectBean(projectId);
		for(Iterator iter =pb.getShotgroups().iterator();iter.hasNext();){
			Shotgroup sg = (Shotgroup)iter.next();
			if(sg.getShotgroup()==null){
				ShotGroupBean sgb=new ShotGroupBean(sg);
				LinkedHashSet list=sgb.getAllShots();
				Set epList=sg.getShotgroups();
				request.setAttribute("shotList", list);
				request.setAttribute("epList", epList);
			}
		}
		
		List models=pop.Query("Catemodel", null, null, null);
		List shotModels=new ArrayList();
		for(Iterator iter=models.iterator();iter.hasNext();){
			Catemodel model=(Catemodel)iter.next();
			if(model.getCateModelType().equals("Shot")){
				shotModels.add(model);
			}
		}
		request.setAttribute("shotModels", shotModels);
		request.setAttribute("projectId", projectId);
		return mapping.findForward("show");
	}
}
